package br.com.wepa.webapps.orca.logica.persistencia.search;

import javax.persistence.PersistenceException;

import br.com.wepa.webapps.search.Search;
import br.com.wepa.webapps.search.SearchResult;

public class NamedQuerySearch<T> extends DefaultSearch<T> implements Search{
	
	private String queryName;
	private Object[] params;
	

	public NamedQuerySearch(String queryName, Object... params){
		this.queryName = queryName;
		this.params = params;
	}	
	
	/**
	 * Execute the search if find is enabled
	 */
	@SuppressWarnings("unchecked")
	public SearchResult<T> find() throws PersistenceException {	
		if(isFindEnabled()){
			setSearchResult(getPersistence().searchNamedQuery(this));
		}
		return getSearchResult();
	}
	
	public Object[] getParams() {
		return params;
	}
	
	public Object getParam(int i) {
		return params[i];
	}
	public void setParams(Object[] params) {
		this.params = params;
	}
	public String getQueryName() {
		return queryName;
	}
	public void setQueryName(String queryName) {
		this.queryName = queryName;
	}
	

}
